﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using Microsoft.AspNetCore.Authorization
@inject IAuthorizationService authorizationService;
@model IEnumerable<IdentityRole>  
@{
    ViewBag.Title = "角色列表";
}
<h1>所有角色列表</h1>
@if (Model.Any())
{
    <a class="btn btn-primary mb-3" style="width: auto" asp-action="CreateRole" asp-controller="Admin">添加新角色</a>

    @foreach (var role in Model)
    {
        <div class="mb-3">
            <div class="card-header">角色ID：@role.Id</div>
            <div class="card-body">
                <h5 class="card-title">@role.Name</h5>
            </div>
            <div class="card-footer">
                <form method="post" asp-controller="Admin" asp-action="DeleteRole" asp-route-id="@role.Id">
                    @if ((await authorizationService.AuthorizeAsync(User, "EditRolePolicy")).Succeeded)
                    {
                        <a class="btn btn-primary" asp-controller="Admin" asp-action="EditRole" asp-route-id="@role.Id">编辑</a>
                    }

                    <span id="confirmDeleteSpan_@role.Id" style="display: none">
                        <span>你确定要删除？</span>
                        <button type="submit" class="btn btn-danger">是</button>
                        <a href="#" class="btn btn-primary" onclick="confirmDelete('@role.Id', false)">否</a>
                    </span>
                    <span id="deleteSpan_@role.Id">
                        <a href="#" class="btn btn-danger" onclick="confirmDelete('@role.Id', true)">删除</a>
                    </span>
                </form>
            </div>
        </div>
    }
}
else
{
    <div class="card">
        <div class="card-header">尚未创建任何角色</div>
        <div class="card-body">
            <h5 class="card-title">单击下面按钮创建角色</h5>
            <a class="btn btn-primary" style="width: auto" asp-action="CreateRole" asp-controller="Admin">创建角色</a>
        </div>
    </div>
}
@section Scripts
{
    <script src="~/js/CustomScript.js" asp-append-version="true"></script>
}
